<script>
  const obj = {
    name:'cp',
    age:20,
    height:180
  }
  const keys = ['height','name','age']

  /**
   * { height:180, name: 'cp', age: 20}
   * 
   */
  function formatObj(){
    const newObj = {}
    keys.forEach(key=>{
      // key = height  newObj['height'] = 180
      // key = name newObj['name']  = 'cp'
      // key = age  newObj['age'] = 20
      newObj[key] = obj[key]
    })
  }

</script>